package com.bjsxt.user.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.commom.Util.PageInfoUtil;
import com.bjsxt.user.dao.IAUserDao;
import com.bjsxt.user.pojo.AUser;
import com.bjsxt.user.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService
{
	@Resource
	private IAUserDao userDao;
	
	@Override
	public AUser findUserService(String type, Map<String, Object> sourceMap)
	{
		return this.userDao.findOne(type, sourceMap);
	}
	/**
	 * @return code:1 表示成功 0 表示失败
	 * 
	 */
	@Override
	public JSONObject insertUserService(AUser user)
	{
		JSONObject jsonObject = new JSONObject();
		int insert = this.userDao.insert(user);
		if(insert>0)
		{
			jsonObject.put("code", "1");
			jsonObject.put("info", "用户添加成功");
			JSONObject data = new JSONObject();
			data.put("id", insert);
			jsonObject.put("data", data);
		}else
		{
			jsonObject.put("code", "0");
			jsonObject.put("info", "用户添加失败");
		}
		return jsonObject;
	}
	@Override
	public JSONObject deleteUserService(AUser user)
	{
		JSONObject jsonObject = new JSONObject();
		int delete = this.userDao.delete(user);
		if(delete>0)
		{
			jsonObject.put("code", "1");
			jsonObject.put("info", "用户删除成功");
			JSONObject data = new JSONObject();
			data.put("id", delete);
			jsonObject.put("data", data);
		}else
		{
			jsonObject.put("code", "0");
			jsonObject.put("info", "用户删除失败");
		}
		return jsonObject;
	}
	@Override
	public JSONObject updateUserService(AUser user)
	{
		JSONObject jsonObject = new JSONObject();
		int update = this.userDao.update(user);
		if(update>0)
		{
			jsonObject.put("code", "1");
			jsonObject.put("info", "用户更新成功");
			JSONObject data = new JSONObject();
			data.put("id", update);
			jsonObject.put("data", data);
		}else
		{
			jsonObject.put("code", "0");
			jsonObject.put("info", "用户更新失败");
		}
		return jsonObject;
	}
	@Override
	public List<AUser> findUserListService(PageInfoUtil pageInfoUtil, Map<String, Object> sourceMap)
	{
		return this.userDao.findList(pageInfoUtil, "", sourceMap);
	}

}
